//app.js
import store from './store/index.js'
App({
  onLaunch: function () {
    this.getTotalCount()
    store.subscribe(this.getTotalCount)
  },
  /**
   * 计算商品总数
   */
  getTotalCount() {
    let amount = store.getState().cart.cartList.reduce((result, item) => {
      result += item.count
      return result
    }, 0).toString()
    wx.setTabBarBadge({
      index: 2,
      text: amount
    })
  },
})